package cloud.xiguapi.ubas.analysis.uv.model;

import cloud.xiguapi.ubas.model.UserBehavior;
import org.apache.flink.streaming.api.windowing.triggers.Trigger;
import org.apache.flink.streaming.api.windowing.triggers.TriggerResult;
import org.apache.flink.streaming.api.windowing.windows.TimeWindow;

/**
 * @author 大大大西西瓜皮🍉
 * date: 2021-5-19 上午 09:55
 * desc:
 */
public class UVTrigger extends Trigger<UserBehavior, TimeWindow> {

    @Override
    public TriggerResult onElement(UserBehavior element, long timestamp, TimeWindow window, TriggerContext ctx) throws Exception {
        // 每一条数据到来, 直接触发窗口计算, 且直接清空窗口
        return TriggerResult.FIRE_AND_PURGE;
    }

    @Override
    public TriggerResult onProcessingTime(long time, TimeWindow window, TriggerContext ctx) {
        return TriggerResult.CONTINUE;
    }

    @Override
    public TriggerResult onEventTime(long time, TimeWindow window, TriggerContext ctx) {
        return TriggerResult.CONTINUE;
    }

    @Override
    public void clear(TimeWindow window, TriggerContext ctx) throws Exception {

    }
}
